home *** CD-ROM | disk | FTP | other *** search
- Path: news.halcyon.com!usenet
- From: normanb@halcyon.com (Norm Bryar)
- Newsgroups: comp.lang.c++
- Subject: Re: C calling C++ function????
- Date: Mon, 19 Feb 1996 18:26:56 GMT
- Organization: Northwest Nexus Inc.
- Message-ID: <4gafce$84m@news.halcyon.com>
- References: <4g07q4$doh@ornews.intel.com> <DMvKCH.Iwo@tr.unisys.com>
- NNTP-Posting-Host: blv-pm12-ip19.halcyon.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- Something tells me it's not that simple.
-
- First, a 'C' compiler probably wouldn't know about the existence of a
- vtable, let alone that it can be accessed via .vtab as if it were a
- struct member. When I say sizeof(myclass), I get the size of the data
- members exactly, no additional bytes suggesting function pointers or
- vtables. You'll have to provide sample code I can compiler on MSVC4
- before I'll accept it.
-
- Second, you seem to have forgotten about name mangling:
- bar() is really @@bar@4@lots_of_other_crap. I don't believe you
- can extern "C" methods, so the name will always be decorated somehow.
- If you knew the mangling, you could use that name, but then changing
- from VC2.2 to VC4.0 might break you, changing from VC to Gnu g++
- certainly would break you.
-
- I believe the accepted thing to do is define a set of 'C' wrapper APIs
- that you can export to your 'C' modules. Internally, your wrappers do
- class method calls.
-
- ---Norm
-
-
- "Benjamin M. Romer" <bmr1@trpo4.tr.unisys.com> wrote:
-
- >easy.
-
- >if you want to call the foo object's bar function, you just need
- >to call
-
- >foo.vtab->bar(foo, ...)
-
- >vtab may be vftab or vfstab, can't remember off the top of my head,
- >though.
-
- >Hope this helps.
-
-
- >Benjamin M. Romer
- >Software Engineer
- >Unisys Corporation
-
- >#include <stddisclaim.h>
-
-
-
-
-